package com.xiaoran.RMQ_1.test3;

import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import com.xiaoran.RMQ_1.utlis.RabbitMqUtils;
import com.xiaoran.RMQ_1.utlis.SleepUtile;

public class ACK_Consumer_2 {
    public static final  String QUEUE_NAME="ack_queue";
    public static void main(String args[]) throws Exception{
        System.out.println("我是C2消费者，我的消费时间较长");
        Channel channel= RabbitMqUtils.getChannel();
        //成功回调函数
        DeliverCallback deliverCallback=(consumerTag, message)->{
            //沉睡一下
            SleepUtile.sleep(10);
            System.out.println("接收到的消息是："+new String(message.getBody()));
            channel.basicAck(message.getEnvelope().getDeliveryTag(),false);
        };
        //失败回调函数
        CancelCallback cancelCallback= consumerTag->{
            System.out.println(consumerTag+"很遗憾失败了，不要放弃还有机会");
        };
        //开启不公平分发
        //channel.basicQos(1);
        //开启预取值
        channel.basicQos(5);
        channel.basicConsume(QUEUE_NAME,false,deliverCallback,cancelCallback);
    }
}